package gui;

import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;

import managers.Print;

public class MainWindowGUI {
	private JFrame mainFrame;
	private JMenuBar menuBar;
	private JMenu menu, menu1, menu2, menu3, menu4;
	private JMenuItem exitMI, addMemberMI, showMembersMI, aboutMI,
						addContingentMI, renewContingentMI, sendMailMI, userGuideMI;
	private JLabel picLbl, headerLbl;
	private Container pane;

	public MainWindowGUI() {
		
		Font myFont = new Font("Arial", Font.BOLD, 18);
		headerLbl = new JLabel("Kocatepe Camii");
		headerLbl.setFont(myFont);		
		try {
			picLbl = new JLabel(new ImageIcon(ImageIO.read(new File("src/mosque.jpg"))));
		} catch(IOException e) {
			System.out.println("Image doesn't exist!!!");
		}
		
		pane = new Container();
		pane.setLayout(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();
		c.fill = GridBagConstraints.HORIZONTAL;
		c.gridwidth = 3;
		c.weightx = 0.0;
		pane.add(headerLbl, c);
	
		menuBar = new JMenuBar();
		//menuBar.setBackground(new Color(224, 230, 232));
		
		menu = new JMenu("Fil");
		menu.setMnemonic(KeyEvent.VK_A);	
		
		exitMI = new JMenuItem("Exit");
		exitMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
		exitMI.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				System.exit(0);
			}
		});
		
		menu.add(exitMI);
		
		showMembersMI = new JMenuItem("Vis Medlemmer");
		showMembersMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK));
		showMembersMI.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				ShowMembersGUI showMembersGUI = new ShowMembersGUI();
				showMembersGUI.showGUI();
			}
		});
		
		addMemberMI = new JMenuItem("Tilføj Medlem");
		addMemberMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, ActionEvent.CTRL_MASK));
		addMemberMI.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				AddMemberGUI addMemberGUI= new AddMemberGUI();
				addMemberGUI.showGUI();
			}
		});
		
		menu1 = new JMenu("Medlem");
		menu1.add(showMembersMI);
		menu1.addSeparator();
		menu1.add(addMemberMI);
		
		addContingentMI = new JMenuItem("Opret       ");
		addContingentMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
		addContingentMI.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				AddContingentGUI addContingentGUI = new AddContingentGUI();
				addContingentGUI.showGUI();
			}
		});
		
		renewContingentMI = new JMenuItem("Forny     ");
		renewContingentMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, ActionEvent.CTRL_MASK));
		renewContingentMI.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				RenewContingentGUI renewContingentGUI = new RenewContingentGUI();
				renewContingentGUI.showGUI();
				
			}	
		});
		
		menu2 = new JMenu("Kontingent");
		menu2.add(addContingentMI);
		menu2.add(renewContingentMI);
		
		sendMailMI = new JMenuItem("Send Mail");
		sendMailMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));

		sendMailMI.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				SendMailGUI sendMailGUI = new SendMailGUI();
				sendMailGUI.showGUI();
			}	
		});
		
		menu3 = new JMenu("Mail");
		menu3.add(sendMailMI);
		
		userGuideMI = new JMenuItem("Brugervejledning");
		userGuideMI.addActionListener(new ActionListener()  {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				UserGuideGUI userGuideGUI = new UserGuideGUI();
				userGuideGUI.showGUI();
			}
			
		});
		
		aboutMI = new JMenuItem("Om");
		aboutMI.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				AboutGUI aboutGUI = new AboutGUI();
				aboutGUI.showGUI();
			}	
		});
		
		
		menu4 = new JMenu("Hjælp");
		menu4.add(userGuideMI);
		menu4.add(aboutMI);
		
		menuBar.add(menu);
		menuBar.add(menu1);
		menuBar.add(menu2);
		menuBar.add(menu3);
		menuBar.add(menu4);
		
	}
	
	public void showGUI() {
		
		mainFrame = new JFrame("Kocatepe Cami");
		Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); 
		int w = mainFrame.getSize().width;
		int h = mainFrame.getSize().height;
		int x = (dim.width-w)/4;
		int y = (dim.height-h)/4;
		mainFrame.setJMenuBar(menuBar);
		mainFrame.setContentPane(pane);
		mainFrame.setLocation(x, y);
		mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		mainFrame.setSize(600, 400);
		mainFrame.setResizable(false);
		mainFrame.setLocationByPlatform(true);
		mainFrame.setVisible(true);
	}
}
